/*
** grh_action.c for zappy in /home/guidet_m/TECK2/projets/zappy/server_zappy
** 
** Made by michael guidet
** Login   <guidet_m@epitech.net>
** 
** Started on  Mon Jul  4 15:37:38 2011 michael guidet
** Last update Mon Jul  4 15:37:39 2011 michael guidet
*/

#include "server.h"

void	map_size(t_fd *fd, t_env *e, char *cmd)
{
  char	cmd2[BUF_SIZE];

  sprintf(cmd2, "msz %d %d\n", e->width, e->height);
  add_string_to_list(&fd->send_list, cmd2);
  cmd = cmd;
}

void	grh_bct(t_fd *fd, t_env *e, char *cmd)
{
  char	cmd2[BUF_SIZE];
  int	r;
  int	x;
  int	y;

  r = x_int(-1, sscanf(cmd, "bct %d %d", &x, &y), "sscanf");
  if (r != 2 || x < 0 || x >= e->width || y < 0 || y >= e->height)
    {
      add_string_to_list(&fd->send_list, "sbp\n");
      return ;
    }
  sprintf(cmd2, "bct %d %d %d %d %d %d %d %d %d\n", x, y,
	  e->map[y][x].ressource[NOURRITURE], e->map[y][x].ressource[LINEMATE],
	  e->map[y][x].ressource[DERAUMERE], e->map[y][x].ressource[SIBUR],
	  e->map[y][x].ressource[MENDIANE], e->map[y][x].ressource[PHIRAS],
	  e->map[y][x].ressource[THYSTAME]);
  add_string_to_list(&fd->send_list, cmd2);
}

void	grh_mct(t_fd *fd, t_env *e, char *cmd)
{
  char	cmd2[BUF_SIZE];
  int	y;
  int	x;

  for (y = 0; y < e->height; y++)
    for (x = 0; x < e->width; x++)
      {
	sprintf(cmd2, "bct %d %d %d %d %d %d %d %d %d\n", x, y,
		e->map[y][x].ressource[NOURRITURE], e->map[y][x].ressource[LINEMATE],
		e->map[y][x].ressource[DERAUMERE], e->map[y][x].ressource[SIBUR],
		e->map[y][x].ressource[MENDIANE], e->map[y][x].ressource[PHIRAS],
		e->map[y][x].ressource[THYSTAME]);
	add_string_to_list(&fd->send_list, cmd2);
      }
  cmd = cmd;
}

void	grh_tna(t_fd *fd, t_env *e, char *cmd)
{
  char	cmd2[BUF_SIZE];
  int	i;

  for (i = 0; e->teams[i].name; i++)
    {
      sprintf(cmd2, "tna %s\n", e->teams[i].name);
      add_string_to_list(&fd->send_list, cmd2);
    }
    cmd = cmd;
}
